package com.example.dllo.my36kr.share.all;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.SeekBar;
import android.widget.TextView;

import com.example.dllo.my36kr.R;
import com.example.dllo.my36kr.find.FindFragment;
import com.example.dllo.my36kr.tools.NetTool;

import java.util.ArrayList;

/**
 * Created by dllo on 16/8/17.
 */
public class AllAdapter extends BaseAdapter {
    Context mContext;
    AllBean allBeen;
    private final NetTool netTool;


    public AllAdapter(Context mContext) {
        this.mContext = mContext;
        netTool = new NetTool();
    }

    public void setAllBeen(AllBean allBeen) {
        this.allBeen = allBeen;
    }

    @Override
    public int getCount() {
        return allBeen != null ? allBeen.getData().getData().size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        AllViewHolder holder =null;
        if (convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.fragment_share_all_item,null);
            holder = new AllViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (AllViewHolder) convertView.getTag();
        }
        netTool.getImage(allBeen.getData().getData().get(position).getCompany_logo(),holder.companyLogoIv);
        netTool.getImage(allBeen.getData().getData().get(position).getFile_list_img(),holder.fileListImgIv);
        holder.companyNameTv.setText(allBeen.getData().getData().get(position).getCompany_name());
        holder.companyBriefTv.setText(allBeen.getData().getData().get(position).getCompany_brief());
        holder.leadNameTv.setText(allBeen.getData().getData().get(position).getLead_name());
        holder.adnameChuangTv.setText(allBeen.getData().getData().get(position).getCf_advantage().get(0).getAdname());
        holder.adcontentChuangTv.setText(allBeen.getData().getData().get(position).getCf_advantage().get(0).getAdcontent());
        holder.adcontentTv.setText(allBeen.getData().getData().get(position).getCf_advantage().get(1).getAdcontent());
        holder.adnameTv.setText(allBeen.getData().getData().get(position).getCf_advantage().get(1).getAdname());
        holder.descTv.setText(allBeen.getData().getData().get(position).getFundStatus().getDesc());
        int schedule = (int) (allBeen.getData().getData().get(position).getRate()*100);
        holder.rateTv.setText("已募资"+schedule + "%");
        if (schedule < 100){
            holder.seekBar.setProgress(schedule);
        }else if (schedule >= 100){
            holder.seekBar.setProgress(100);
        }
        if (schedule >= 80){
            holder.bntQk.setText("去看看");
            holder.bntQk.setTextColor(Color.BLACK);
            holder.bntQk.setBackgroundColor(Color.WHITE);
        }else if (schedule < 80){
            holder.bntQk.setText("认购");
            holder.bntQk.setBackgroundColor(Color.MAGENTA);
        }

        return convertView;
    }
    public class AllViewHolder{
        ImageView companyLogoIv,fileListImgIv;
        TextView companyNameTv,companyBriefTv,leadNameTv,adnameChuangTv,adcontentChuangTv,adnameTv,adcontentTv,descTv,rateTv;
        ProgressBar seekBar;
        Button bntQk;
        public AllViewHolder(View view) {
            companyLogoIv = (ImageView) view.findViewById(R.id.iv_share_all_company_logo);
            fileListImgIv = (ImageView) view.findViewById(R.id.iv_share_all_file_list_img);
            companyNameTv = (TextView) view.findViewById(R.id.tv_share_all_company_name);
            companyBriefTv = (TextView) view.findViewById(R.id.tv_share_all_company_brief);
            leadNameTv = (TextView) view.findViewById(R.id.tv_share_all_lead_name);
            adcontentChuangTv = (TextView) view.findViewById(R.id.tv_share_all_adcontent_chenggong);
            adnameChuangTv = (TextView) view.findViewById(R.id.tv_share_all_adname_chuangshiren);
            adnameTv = (TextView) view.findViewById(R.id.tv_share_all_adname_fuhuaqi);
            adcontentTv= (TextView) view.findViewById(R.id.tv_share_all_adcontent_fuhuaqi);
            descTv = (TextView) view.findViewById(R.id.tv_share_all_desc);
            rateTv = (TextView) view.findViewById(R.id.tv_share_all_rate);
            seekBar = (ProgressBar) view.findViewById(R.id.sb_share_all);
            bntQk = (Button) view.findViewById(R.id.bnt_share_all_qukankan);



        }
    }
}
